home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Comm / www / tidy_os4.lha / tidy / src / config.h < prev    next >
C/C++ Source or Header  |  2004-07-25  |  6KB  |  182 lines

  1. #ifndef __CONFIG_H__
  2. #define __CONFIG_H__
  3.  
  4. /* config.h -- read config file and manage config properties
  5.   
  6.   (c) 1998-2004 (W3C) MIT, ERCIM, Keio University
  7.   See tidy.h for the copyright notice.
  8.  
  9.   CVS Info :
  10.  
  11.     $Author: terry_teague $ 
  12.     $Date: 2004/02/29 03:55:50 $ 
  13.     $Revision: 1.6 $ 
  14.  
  15.   config files associate a property name with a value.
  16.  
  17.   // comments can start at the beginning of a line
  18.   # comments can start at the beginning of a line
  19.   name: short values fit onto one line
  20.   name: a really long value that
  21.    continues on the next line
  22.  
  23.   property names are case insensitive and should be less than
  24.   60 characters in length and must start at the begining of
  25.   the line, as whitespace at the start of a line signifies a
  26.   line continuation.
  27.  
  28. */
  29.  
  30. #include "forward.h"
  31. #include "tidy.h"
  32. #include "streamio.h"
  33.  
  34. struct _tidy_option;
  35. typedef struct _tidy_option TidyOptionImpl;
  36.  
  37. typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt );
  38.  
  39. struct _tidy_option
  40. {
  41.     TidyOptionId        id;
  42.     TidyConfigCategory  category;   /* put 'em in groups */
  43.     ctmbstr             name;       /* property name */
  44.     TidyOptionType      type;       /* string, int or bool */
  45.     ulong               dflt;       /* factory default */
  46.     ParseProperty*      parser;     /* parsing method, read-only if NULL */
  47.     const ctmbstr*      pickList;   /* pick list */
  48. };
  49.  
  50.  
  51. typedef struct _tidy_config
  52. {
  53.     ulong value[ N_TIDY_OPTIONS + 1 ];     /* current config values */
  54.     ulong snapshot[ N_TIDY_OPTIONS + 1 ];  /* Snapshot of values to be restored later */
  55.  
  56.     /* track what tags user has defined to eliminate unnecessary searches */
  57.     uint  defined_tags;
  58.  
  59.     uint c;           /* current char in input stream */
  60.     StreamIn* cfgIn;  /* current input source */
  61.  
  62. } TidyConfigImpl;
  63.  
  64.  
  65. const TidyOptionImpl* lookupOption( ctmbstr optnam );
  66. const TidyOptionImpl* getOption( TidyOptionId optId );
  67.  
  68. TidyIterator getOptionList( TidyDocImpl* doc );
  69. const TidyOptionImpl*  getNextOption( TidyDocImpl* doc, TidyIterator* iter );
  70.  
  71. TidyIterator getOptionPickList( const TidyOptionImpl* option );
  72. ctmbstr getNextOptionPick( const TidyOptionImpl* option, TidyIterator* iter );
  73.  
  74. void InitConfig( TidyDocImpl* doc );
  75. void FreeConfig( TidyDocImpl* doc );
  76.  
  77. Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val );
  78. Bool SetOptionInt( TidyDocImpl* doc, TidyOptionId optId, ulong val );
  79. Bool SetOptionBool( TidyDocImpl* doc, TidyOptionId optId, Bool val );
  80.  
  81. Bool ResetOptionToDefault( TidyDocImpl* doc, TidyOptionId optId );
  82. void ResetConfigToDefault( TidyDocImpl* doc );
  83. void TakeConfigSnapshot( TidyDocImpl* doc );
  84. void ResetConfigToSnapshot( TidyDocImpl* doc );
  85.  
  86. void CopyConfig( TidyDocImpl* docTo, TidyDocImpl* docFrom );
  87.  
  88. /*
  89.  Todd Lewis contributed this code for expanding
  90.  ~/foo or ~your/foo according to $HOME and your
  91.  user name. This will only work on Unix systems.
  92. */
  93. ctmbstr ExpandTilde(ctmbstr filename);
  94.  
  95. int  ParseConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
  96. int  ParseConfigFileEnc( TidyDocImpl* doc,
  97.                          ctmbstr cfgfil, ctmbstr charenc );
  98.  
  99. int  SaveConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
  100. int  SaveConfigSink( TidyDocImpl* doc, TidyOutputSink* sink );
  101.  
  102. /* returns false if unknown option, missing parameter, or
  103.    option doesn't use parameter
  104. */
  105. Bool  ParseConfigOption( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
  106. Bool  ParseConfigValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
  107.  
  108. /* ensure that char encodings are self consistent */
  109. Bool  AdjustCharEncoding( TidyDocImpl* doc, int encoding );
  110.  
  111. /* ensure that config is self consistent */
  112. void AdjustConfig( TidyDocImpl* doc );
  113.  
  114. Bool  ConfigDiffThanDefault( TidyDocImpl* doc );
  115. Bool  ConfigDiffThanSnapshot( TidyDocImpl* doc );
  116.  
  117. int CharEncodingId( ctmbstr charenc );
  118. ctmbstr CharEncodingName( int encoding );
  119.  
  120. void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename );
  121.  
  122.  
  123. #ifdef _DEBUG
  124.  
  125. /* Debug lookup functions will be type-safe and assert option type match */
  126. ulong   _cfgGet( TidyDocImpl* doc, TidyOptionId optId );
  127. Bool    _cfgGetBool( TidyDocImpl* doc, TidyOptionId optId );
  128. ctmbstr _cfgGetString( TidyDocImpl* doc, TidyOptionId optId );
  129.  
  130. #define cfg(doc, id)            _cfgGet( (doc), (id) )
  131. #define cfgBool(doc, id)        _cfgGetBool( (doc), (id) )
  132. #define cfgStr(doc, id)         _cfgGetString( (doc), (id) )
  133.  
  134. #else
  135.  
  136. /* Release build macros for speed */
  137. #define cfg(doc, id)            ((doc)->config.value[ (id) ])
  138. #define cfgBool(doc, id)        ((Bool) cfg(doc, id))
  139. #define cfgStr(doc, id)         ((ctmbstr) cfg(doc, id))
  140.  
  141. #endif /* _DEBUG */
  142.  
  143.  
  144.  
  145. /* parser for integer values */
  146. ParseProperty ParseInt;
  147.  
  148. /* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no' or '1'/'0' */
  149. ParseProperty ParseBool;
  150.  
  151. /* a string excluding whitespace */
  152. ParseProperty ParseName;
  153.  
  154. /* a CSS1 selector - CSS class naming for -clean option */
  155. ParseProperty ParseCSS1Selector;
  156.  
  157. /* a string including whitespace */
  158. ParseProperty ParseString;
  159.  
  160. /* a space or comma separated list of tag names */
  161. ParseProperty ParseTagNames;
  162.  
  163. /* RAW, ASCII, LATIN0, LATIN1, UTF8, ISO2022, MACROMAN, 
  164.    WIN1252, IBM858, UTF16LE, UTF16BE, UTF16, BIG5, SHIFTJIS
  165. */
  166. ParseProperty ParseCharEnc;
  167. ParseProperty ParseNewline;
  168.  
  169. /* specific to the indent option - Bool and 'auto' */
  170. ParseProperty ParseIndent;
  171.  
  172. /* omit | auto | strict | loose | <fpi> */
  173. ParseProperty ParseDocType;
  174.  
  175. /* keep-first or keep-last? */
  176. ParseProperty ParseRepeatAttr;
  177.  
  178. /* specific to the output-bom option - Bool and 'auto' */
  179. ParseProperty ParseBOM;
  180.  
  181. #endif /* __CONFIG_H__ */
  182.